#include "dialog_yp.h"
#include "ui_dialog_yp.h"
#include "dialog_sql.h"
#include "mysql.h"
#include "dialog_msbox.h"
Dialog_yp::Dialog_yp(test *da,QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dialog_yp)
{
    ui->setupUi(this);

    buffer=da;

    this->setWindowFlags(Qt::FramelessWindowHint);

    t_btn_no=ui->btn_no;
    connect(ui->btn_no,&QPushButton::clicked,[=]{done(ENM_no_BTN);});


    ui->test_id->setText(buffer->info.test_id);
    ui->test_md->setText(buffer->info.test_md);
    ui->test_hd->setText(buffer->info.test_hd);
    ui->test_gz->setText(buffer->info.test_gz);
    ui->test_tj->setText(buffer->info.test_tj);
    ui->test_Ddate->setText(buffer->info.test_Ddate);
    ui->test_scdm->setText(buffer->info.test_scdm);
    ui->test_sjdm->setText(buffer->info.test_sjdm);
    ui->test_syxx->append(buffer->info.test_syxx);
    ui->test_sybz->append(buffer->info.test_sybz);


}

Dialog_yp::~Dialog_yp()
{
    delete ui;
}
int Dialog_yp::show(test *buffer, QWidget *parent)
{

    Dialog_yp box(buffer,parent);

    test_info p;

    return box.exec();

}

void Dialog_yp::on_save_clicked()
{

    int ret=Dialog_msbox::show(1,1,"信息保存","Information saving","请注意，是否对试验样品数据进行保存？");
    if(ret==1)
    {
        buffer->info.test_id=ui->test_id->text();
        buffer->info.test_md=ui->test_md->text();
        buffer->info.test_hd=ui->test_hd->text();
        buffer->info.test_gz=ui->test_gz->text();
        buffer->info.test_tj=ui->test_tj->text();
        buffer->info.test_Ddate=ui->test_Ddate->text();
        buffer->info.test_scdm=ui->test_scdm->text();
        buffer->info.test_sjdm=ui->test_sjdm->text();
        buffer->info.test_syxx=ui->test_syxx->document()->toHtml();
        buffer->info.test_sybz=ui->test_sybz->document()->toHtml();

        mysql::INSERT_test_info(buffer->info);
        done(ENM_yes_BTN);
    }
}

void Dialog_yp::on_sql_clicked()
{
    int ret=Dialog_sql::show(buffer);
    if(ret==1)
    {
        ui->test_id->setText(buffer->info.test_id);
        ui->test_md->setText(buffer->info.test_md);
        ui->test_hd->setText(buffer->info.test_hd);
        ui->test_gz->setText(buffer->info.test_gz);
        ui->test_tj->setText(buffer->info.test_tj);
        ui->test_Ddate->setText(buffer->info.test_Ddate);
        ui->test_scdm->setText(buffer->info.test_scdm);
        ui->test_sjdm->setText(buffer->info.test_sjdm);
        ui->test_syxx->clear();
        ui->test_sybz->clear();
        ui->test_syxx->append(buffer->info.test_syxx);
        ui->test_sybz->append(buffer->info.test_sybz);
    }
}
